using System;
using System.Windows.Forms;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;

namespace GCalSync
{
    public partial class ThisApplication
    {
        private GlobalObjects internalObjects;
        private Office.CommandBarButton toolbarButton;

        private void ThisApplication_Startup(object sender, System.EventArgs e)
        {
            // Create home for long lived objects. (No Garbage Collection with these)
            internalObjects = new GlobalObjects(this);
            GlobalObjects.activeExplorer = GlobalObjects.outlookApplication.ActiveExplorer();

            Office.CommandBars commandBars = this.ActiveExplorer().CommandBars;
            // Create a toolbar button on the standard toolbar that calls ToolbarButton_Click when clicked
            try
            {
                // See if it already exists
                this.toolbarButton = (Office.CommandBarButton)commandBars["Standard"].Controls["GCal Sync"];
            }
            catch (Exception)
            {
                // Create it
                this.toolbarButton = (Office.CommandBarButton)commandBars["Standard"].Controls.Add(1, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                this.toolbarButton.Caption = "GCal Sync";
                this.toolbarButton.Style = Office.MsoButtonStyle.msoButtonCaption;
            }
            this.toolbarButton.Tag = "Hello Button";
            this.toolbarButton.OnAction = "!<MyAddin1.Connect>";
            this.toolbarButton.Visible = true;
            this.toolbarButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(toolbarButton_Click);
        }

        void toolbarButton_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
        {
            SyncForm sync = new SyncForm();
            sync.Show();
        }



        private void ThisApplication_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisApplication_Startup);
            this.Shutdown += new System.EventHandler(ThisApplication_Shutdown);
        }

        #endregion
    }
}
